import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:renqing/pages/edit.dart';
import 'package:renqing/global.dart';

class ListItem extends StatefulWidget {
  ListItem({Key key, this.id, this.data}) : super(key: key);
  final id;
  final data;
  @override
  State<StatefulWidget> createState() => _ListItemState();
}

class _ListItemState extends State<ListItem> {
  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => EditPage(id: widget.id, data: widget.data),
          ),
        );
      },
      child: Container(
        width: MediaQuery.of(context).size.width,
        height: 110,
        margin: EdgeInsets.all(10),
        padding: EdgeInsets.all(10),
        decoration: BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: Global.fontSecondColor.withOpacity(0.2),
              width: 0.5,
              style: BorderStyle.solid,
            ),
          ),
        ),
        child: Row(
          children: [
            Container(
              width: 50,
              height: 50,
              padding: EdgeInsets.all(8),
              decoration: BoxDecoration(
                color: Global.mainColor,
                borderRadius: BorderRadius.circular(100),
              ),
              child: Center(
                child: Text(
                  DateTime.parse(widget.data['date']).month.toString() + '月',
                  style: TextStyle(
                    color: Global.backgroundColor,
                    fontWeight: FontWeight.w600,
                    fontSize: 15,
                  ),
                ),
              ),
            ),
            SizedBox(width: 20),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Text(
                    "${widget.data['name']}（${widget.data['relation']}）",
                    style: TextStyle(
                      color: Global.mainColor,
                      fontWeight: FontWeight.w600,
                      fontSize: 15,
                    ),
                  ),
                  SizedBox(height: 2),
                  Text(
                    "[事由]${widget.data['why']}",
                    style: TextStyle(
                      color: Global.fontColor,
                      fontWeight: FontWeight.w300,
                      fontSize: 13,
                    ),
                  ),
                  SizedBox(height: 2),
                  Text(
                    widget.data['date'],
                    style: TextStyle(
                      color: Global.fontSecondColor,
                      fontWeight: FontWeight.w300,
                      fontSize: 11,
                    ),
                  ),
                ],
              ),
            ),
            Container(
              child: Row(
                children: [
                  Text(
                    widget.data['spending'] ? "送" : "收",
                    style: TextStyle(
                      color: Global.fontSecondColor,
                      fontWeight: FontWeight.w500,
                      fontSize: 15,
                    ),
                  ),
                  SizedBox(width: 5),
                  Text(
                    "￥ ${widget.data['co']}",
                    style: TextStyle(
                      color: widget.data['spending']
                          ? Color(0xFFe84a5f)
                          : Color(0xFF14b1ab),
                      fontWeight: FontWeight.w500,
                      fontSize: 17,
                    ),
                  ),
                ],
              ),
            ),
            Icon(
              Icons.chevron_right,
              color: Global.fontSecondColor,
            )
          ],
        ),
      ),
    );
  }
}
